// pages/addBank/addbank.js
const app = getApp(),util=require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mobile:'',
    veriBtnText:'获取验证码',
    twoalert:false,
    twoalertText:'',
    alerts:false,
    array:[],
    cardType:'',
    type:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  toYonghu(){
    wx.navigateTo({
      url: '../../pages/xieyi/xieyi?type=1',
    })
  },
  qr(){
    let type = this.data.type
    type = !type
    this.setData({
      type
    })
    console.log(this.data.type)
  },
  cancel(){
    let that = this
    that.setData({
      alerts:false,
      twoalert:false,
      twoalertText:"",
    })
  },
  formSubmit(e){
    let that = this
    let value = e.detail.value
    console.log(value)

    if(value.username==''){
      wx.showToast({
        icon:'none',
        title:"姓名不能为空",
      })
      return;
    }else if(value.idcard==''){
      wx.showToast({
        icon:'none',
        title: "身份证不能为空",
      })
      return;
    }else if(value.bankcard==''){
      wx.showToast({
        icon:'none',
        title: "银行卡号不能为空",
      })
      return;
    }else if(value.banktype==''){
      wx.showToast({
        icon:'none',
        title: "卡类型不能为空",
      })
      return;
    }else if(value.phone==''){
      wx.showToast({
        icon:'none',
        title: "手机不能为空",
      })
      return;
    }else if(value.code==''){
      wx.showToast({
        icon:'none',
        title: "验证码不能为空",
      })
      return;
    }else if(that.data.type == false){
      wx.showToast({
        icon:'none',
        title: "请阅读用户协议",
      })
      return;
    }else{
      util.post('bankurl/addcard',{...e.detail.value},function(res){
        console.log(res)
      })
          
    }
  
    // return
   
      
    
      
    
    
  },
  getPhone(e){
    let that = this
    that.setData({
        mobile:e.detail.value
    })
  },
  getCode(){
    
    let that = this, seconds = 60, timer = null , phone = that.data.mobile;
    let regu=/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if(regu.test(phone)){
      timer = setInterval(function () {
        if (seconds > 1) {
          seconds--
          that.setData({
            veriBtnText: '已发送（' + seconds +'S）',
            getting:true
          })
        } else {
          clearInterval(timer)
          that.setData({
            veriBtnText: '重新发送',
            getting:false
          })
        }
      }, 1000)
    }else{
      that.setData({
        alerts:true,
        twoalert:true,
        twoalertText:"手机号有误",
      })
      setTimeout(()=>{
        this.setData({
          alerts:false
        })
      },2000);
    }
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  bindPickerChange(e){
    let index = e.detail.value
    this.setData({
      cardType:this.data.array[index].name
    })
  },
  onShow: function () {
    let that = this
 
    util.post('standard/bankIncome',{},function(res){
      console.log(res)
      that.setData({
        array:res.data.msg
      })
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})